/*
 * Copyright (c) 2024. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package com.neusoft.myspring;

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.security.spec.ECField;
import java.util.HashMap;

public class MySpringContext {

    private static final HashMap<String, Object> beans = new HashMap<>();

    public MySpringContext() {
        try {
            Class clazz = Class.forName("com.neusoft.myspring.Dog");
            MyBean myBean = (MyBean) clazz.getAnnotation(MyBean.class);
            if (myBean.value()) {
                Object o = clazz.getConstructor().newInstance();
                beans.put(myBean.name(), o);
            }

            Class cat = Class.forName("com.neusoft.myspring.Cat");
            myBean = (MyBean) clazz.getAnnotation(MyBean.class);
            if (myBean.value()) {
                Object o = clazz.getConstructor().newInstance();
                beans.put(myBean.name(), o);
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

    public Object getBean(String beanName) {
        return beans.get(beanName);
    }

    public static void main(String[] args) {
        MySpringContext context = new MySpringContext();
        //        Dog dog = (Dog) context.getBean("dog");
        Cat dog = (Cat) context.getBean("cat");
        System.out.println(dog);
    }
}
// ASAM
//
